package com.zxy.supplier_system.server.controller

import com.zxy.supplier_system.server.service.MarketStatisticService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.math.BigDecimal
import java.time.YearMonth

@RestController
@RequestMapping("markets/{id}/statistics")
class MarketStatisticController(
    private val marketStatisticService: MarketStatisticService
) {

//    @GetMapping
//    fun statisticDateTimeRange(@PathVariable id: Int): StatisticDateTimeRangeResponse{
//        return this.marketStatisticService.statisticDateTimeRange(id)
//    }
//
//    data class StatisticDateTimeRangeResponse(
//        /**
//         * 可统计的最早时间
//         */
//        val earliestDateTime:OffsetDateTime?,
//        /**
//         * 可统计的最晚时间
//         */
//        val latestDateTime:OffsetDateTime?,
//    )

    data class MarketStatisticRequest(
        val brandIds:List<Int> = emptyList(),
        val startYearMonth:YearMonth?,
        val endYearMonth:YearMonth?,
    )

    @GetMapping
    fun statistic(@PathVariable id: Int,request: MarketStatisticRequest): MarketStatisticResponse{
        return this.marketStatisticService.statistic(id,request)
    }

    data class MarketStatisticResponse(
        /**
         * 总送货零售价
         */
        val totalPrice:BigDecimal,
        /**
         * 送货单数量
         */
        val deliveryOrderCount:Int,
        /**
         * 总成本
         */
        val totalCost:BigDecimal,
        /**
         * 总销售额
         */
        val totalSoled:BigDecimal,
    )

    @GetMapping("soldGroupByMonth")
    fun soldEveryMonthStatistic(@PathVariable id: Int,request: MarketStatisticRequest): MarketSoldEveryMonthStatisticResponse{
        return this.marketStatisticService.soldStatistic(id,request)
    }

    data class MarketSoldEveryMonthStatisticResponse(
        val yearMonthData: List<YearMonthData>,
    ){
        data class YearMonthData(
            val statisticYearMonth:YearMonth,
            val totalSoled:BigDecimal,
        )
    }


}